﻿namespace EFS.RC.CC.Presences.Operators
{
	/// <summary>
	/// Presences
	/// </summary>
	internal abstract class Deployment<OperatorDeployment> : EFS.RC.CC.Presences.Operators.Presence 
		where OperatorDeployment : EFS.RC.CC.Deployment.Entities.Operator
	{
		#region Composition

		/// Operator deployemnt 
		private OperatorDeployment operatorDeployment = default(OperatorDeployment);

		/// Application
		private EFS.RC.CC.Applications.EndPoints.OfficeService.Operators operatorsOfficeServiceEndPointApplication = null;

		// AD user
		private EFS.AD.User adUser = null;

		#endregion

		#region Constructor

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="operatorDeployment"></param>
		/// <param name="operatorsOfficeServiceEndPointApplication"></param>
		public Deployment(OperatorDeployment operatorDeployment, EFS.RC.CC.Applications.EndPoints.OfficeService.Operators operatorsOfficeServiceEndPointApplication)
		{
			// check
			EFS.Common.Verify.Reference(operatorDeployment, "operatorDeployment");
			EFS.Common.Verify.Reference(operatorsOfficeServiceEndPointApplication, "operatorsOfficeServiceEndPointApplication");

			// set
			this.operatorDeployment = operatorDeployment;
			this.operatorsOfficeServiceEndPointApplication = operatorsOfficeServiceEndPointApplication;

			// load AD data
			adUser = operatorsOfficeServiceEndPointApplication.Domain.GetByGuid(operatorDeployment.DomainOid.Value);

			// check
			EFS.Common.Verify.Reference(adUser, "adUser");
		}

		#endregion

		#region Usage

		/// <summary>
		/// AD User: Get
		/// </summary>
		public override EFS.AD.User User
		{
			get { return adUser; }
		}

		/// <summary>
		/// Deployment: Get
		/// </summary>
		public OperatorDeployment OperatorPresenceDeployment
		{
			get { return operatorDeployment; }
		}

		/// <summary>
		/// End point application
		/// </summary>
		public EFS.RC.CC.Applications.EndPoints.OfficeService.Operators OfficeServiceOperatorEndPointApplication
		{
			get { return operatorsOfficeServiceEndPointApplication; }
		}

		/// <summary>
		/// Describe this
		/// </summary>
		/// <returns></returns>
		public override System.String Describe()
		{
			return System.String.Format("EFS.RC.CC.Presences.Operators.Deployment: {0} Online: {1} Available: {2}", adUser.SIP, IsOnline, IsAvailable);
		}
		
		/// <summary>
		/// Deployment reload
		/// </summary>
		/// <returns></returns>
		public virtual void ReloadDeployment()
		{
			// reload AD data
			adUser = operatorsOfficeServiceEndPointApplication.Domain.GetByGuid(operatorDeployment.DomainOid.Value);
		}

		#endregion
	}
}
